#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int n, m, k;
const int N = 510;
const int M = 1e5 + 10;
int dis[N], backup[N];
typedef struct Edge
{
	int a, b, c;
}edge;
edge e[M];
int Bellman_ford()
{
	memset(dis, 0x3f, sizeof(dis));
	dis[1] = 0;
	for (int j = 0; j < k; j++) {
		memcpy(backup, dis, sizeof(dis));
		for (int i = 0; i < m; i++) {
			int a = e[i].a;
			int b = e[i].b;
			int c = e[i].c;
			dis[b] = min(dis[b], backup[a] + c);
		}
	}
	if (dis[n] > 0x3f3f3f3f / 2) {
		return -1;
	}
	else {
		return dis[n];
	}
}
int main()
{
	cin >> n >> m >> k;
	for (int i = 0; i < m; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		e[i].a = a;
		e[i].b = b;
		e[i].c = c;
	}
	int ret = Bellman_ford();
	if (ret == -1) {
		cout << "impossible" << endl;
	}
	else {
		cout << ret << endl;
	}
	return 0;
}